package com.ruoyi.srmcontract.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.srmcontract.domain.JacContract;
import com.ruoyi.srmcontract.domain.JacContracttemplate;
import com.ruoyi.srmcontract.domain.JacContracttemplate.contractListView;
import com.ruoyi.srmcontract.service.IJacContracttemplateService;
import com.ruoyi.srmcontract.utils.MyUtils;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.core.controller.BaseController;

/**
 * 合同协议模板维护 提供者
 * 
 * @author yanggongxiao
 * @date 2020-07-31
 */
@RestController
@RequestMapping("jacContracttemplate")
public class JacContracttemplateController extends MyUtils
{
	
	@Autowired
	private IJacContracttemplateService jacContracttemplateService;
	
	/**
	 * 查询${tableComment}
	 */
	@GetMapping("get/{contracttemplateId}")
	@JsonView(value = JacContracttemplate.contractListView.class)
	public R get(@PathVariable("contracttemplateId") Long contracttemplateId)
	{
		return jacResult(jacContracttemplateService.selectJacContracttemplateById(contracttemplateId));
		
	}
	
	/**
	 * 查询合同协议模板维护列表
	 */
	@GetMapping("list")
	@JsonView(value = JacContracttemplate.contractListView.class)
	public R list(JacContracttemplate jacContracttemplate)
	{
		startPage();
        return result(jacContracttemplateService.selectJacContracttemplateList(jacContracttemplate));
	}
	
	/**
	 * 查询合同协议模板维护列表
	 */
	@PostMapping("postlist")
	@JsonView(value = JacContracttemplate.contractListView.class)
	public R postList(@RequestBody JacContracttemplate jacContracttemplate)
	{
		startPage();
        return result(jacContracttemplateService.selectJacContracttemplateList(jacContracttemplate));
	}
	
	/**
	 * 查询合同模板的code和name
	 */
	@GetMapping("modelList")
	@JsonView(value = JacContracttemplate.contractModelView.class)
	public R modelList(JacContracttemplate jacContracttemplate)
	{
		startPage();
       return result(jacContracttemplateService.selectTemByPublic(jacContracttemplate));
	}
	
	/**
	 * 生成合同号模板号（如：CT202008030001）
	 */
	@GetMapping("getContractModelCode")
	public R getContractCode()
	{
		startPage();
		return jacResultString("constractCode",jacContracttemplateService.createContractCode("CT"));
	}
	
	/**
	 * 复制合同模板
	 */
	@PostMapping("copyContractModel")
	public R copyContractModel(@RequestBody JacContracttemplate jacContracttemplate)
	{	
		return toAjax(jacContracttemplateService.copyContractModel(jacContracttemplate));
	}
	
    /**
     * 通过合同模板号查询合同协议详情
     * 
     * @param contracttmpcode  合同模板号
     * @return 合同协议详情
     */
	@GetMapping("getDetail/{contracttmpcode}")
	public R getDetail(@PathVariable("contracttmpcode") String contracttmpcode) 
	{
		return jacResultString("detail",jacContracttemplateService.selectDetailByCode(contracttmpcode));
	}
	
	/**
	 * 新增保存合同协议模板维护
	 */
	@PostMapping("save")
	public R addSave(@RequestBody JacContracttemplate jacContracttemplate)
	{	
		return toAjax(jacContracttemplateService.insertJacContracttemplate(jacContracttemplate));
	}

	/**
	 * 修改保存合同协议模板维护
	 */
	@PostMapping("update")
	public R editSave(@RequestBody JacContracttemplate jacContracttemplate)
	{		
		return toAjax(jacContracttemplateService.updateJacContracttemplate(jacContracttemplate));
	}
	
	/**
	 * 修改保存合同协议模板状态
	 */
	@PostMapping("updateStatus")
	public Map<String,String> updateStatus(@RequestBody Map<String,List<JacContracttemplate>> datas)
	{		
		return jacResultMsg(jacContracttemplateService.updateTemStatus(datas));
	}
	
	/**
	 * 删除${tableComment}
	 */
	@PostMapping("remove")
	public Map<String,String> remove(String ids)
	{	
		return jacResultMsg(jacContracttemplateService.deleteJacContracttemplateByIds(ids));
	}
	
}
